package com.zmj.sy.mom.srv.aps.mapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zmj.sy.mom.srv.aps.bean.entity.workshop.WorkshopPlateToPartRes;
import com.zmj.sy.mom.srv.aps.bean.vo.base.BasePageResVo;
import com.zmj.sy.mom.srv.aps.bean.vo.workshop.CheckdPartVo;
import com.zmj.sy.mom.srv.aps.bean.vo.workshop.WorkshopNestPart;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;


@Mapper
public interface WorkshopMapper extends BaseMapper {

    /**
     * @Description: 获取待加工任务列表
     *
     * @author: hejiahui
     * @since: 2024/11/4 14:30
     */
    Page<WorkshopPlateToPartRes> plateToPartList(Page<Object> page, @Param(Constants.WRAPPER) QueryWrapper<?> plateToPartQuery);

    @Select("select part.plate_code, part.part_id , part.quantity, part.net_weight, awo.work_order_code,  o.construct_no " +
            "from tb_third_sinocam_receive_nest_part part " +
            "left join  tb_aps_work_detail awd on part.nest_plan_id = awd.id " +
            "left join tb_aps_work_order awo on awd.aps_work_order_id = awo.id " +
            "left join tb_order_bom ob on awo.bom_id = ob.id " +
            "left join tb_order o on ob.order_id = o.id   ${ew.customSqlSegment}")
    List<WorkshopNestPart> listPlatePart(@Param(Constants.WRAPPER) QueryWrapper<?> query);
    /**
     * @Description: 获取钢板开工人员
     *
     * @author: hejiahui
     * @since: 2024/12/25 10:38
     */
    List<Map<String, Object>> getStartReportList(@Param(Constants.WRAPPER) QueryWrapper<?> reportQuery);
    /**
     * @Description: 获取钢板报工人员
     *
     * @author: hejiahui
     * @since: 2024/12/26 14:45
     */
    List<Map<String, Object>> getEndReportList(@Param(Constants.WRAPPER)QueryWrapper<?> reportQuery);

    @Select("SELECT\n" +
            "\tawd.mater_no AS assemblyNumber,\n" +
            "\tzob.plm_id,\n" +
            "\tMIN( IFNULL( mp.part_count, 0 )/ zob.part_count ) AS totalCount \n" +
            "FROM\n" +
            "\ttb_aps_work_detail awd\n" +
            "\tLEFT JOIN tb_order_bom ob ON awd.mater_no = ob.plm_id\n" +
            "\tLEFT JOIN tb_order_bom zob ON ob.bom_code = zob.parent_bom_code\n" +
            "\tINNER JOIN tb_order tor ON zob.order_id = tor.id \n" +
            "\tAND tor.order_type <> 2 \n" +
            "\tAND tor.deleted = 0 \n" +
            "\tAND tor.order_status = 8\n" +
            "\tLEFT JOIN tb_mes_part mp ON zob.plm_id = mp.plm_id \n" +
            "\tAND mp.phase_code = 'KJ' \n" +
            "WHERE\n" +
            "\tawd.STATUS < 4 \n" +
            "\tAND awd.mater_no = #{plmid} \n" +
            "GROUP BY\n" +
            "\tawd.mater_no,\n" +
            "\tzob.plm_id ")
    List<CheckdPartVo> checkdPart(String plmid);
}
